{% extends 'admin/common/base.html' %}
{% block css %}
{{super()}}
<link href="{{url_for('admin.static',filename='ajax/libs/jasny/jasny-bootstrap.min.css')}}?v=3.1.3" rel="stylesheet" />
<link href="{{url_for('admin.static',filename='ajax/libs/summernote/summernote.css')}}" rel="stylesheet" />
<link href="{{url_for('admin.static',filename='ajax/libs/summernote/summernote-bs3.css')}}" rel="stylesheet" />
{% endblock %}
{% block body %}

<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form">
			<input type="hidden" name="id" value="{{d.id}}">
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">参数名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="sname" id="sname" value="{{d.sname}}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">参数键名：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="skey" id="skey" value="{{d.skey}}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">输入类型：</label>
				<div class="col-sm-8">
					<select class="form-control" id="col_type" name="col_type" required>
						<option value="string" {{'selected' if d.col_type=='text' else '' }}>文本</option>
						<option value="file" {{'selected' if d.col_type=='file' else '' }}>图片/文件</option>
						<option value="richtext" {{'selected' if d.col_type=='richtext' else '' }}>富文本</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">参数键值：</label>
				<input type="hidden" id="origin_svalue" value="{{d.svalue}}">
				<div class="col-sm-8" id="input_type">
					{% if d.col_type == 'file' %}
					<div class="fileinput fileinput-new input-group" data-provides="fileinput">
						<div class="form-control" data-trigger="fileinput"><i
								class="glyphicon glyphicon-file fileinput-exists"></i> <span
								class="fileinput-filename">{{d.svalue}}</span></div>
						<span class="input-group-addon btn btn-white btn-file"><span
								class="fileinput-new">选择文件</span><span class="fileinput-exists">更改</span><input
								type="file" name="svalue"></span>
						<a href="#" class="input-group-addon btn btn-white fileinput-exists"
							data-dismiss="fileinput">清除</a>
					</div>
					{% elif d.col_type == 'richtext' %}
					<textarea class="form-control summernote" name="svalue" id="svalue" value="{{d.svalue}}"
						required>{{d.svalue}}</textarea>
					{% else %}
					<textarea class="form-control" name="svalue" id="svalue" value="{{d.svalue}}"
						required>{{d.svalue}}</textarea>
					{% endif %}
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<textarea id="remark" name="remark" class="form-control">{{d.remark}}</textarea>
				</div>
			</div>
			<!-- <div class="text-center" style="color:red;">**修改系统参数需要重启系统服务才能完全生效**</div> -->
		</form>
	</div>
</body>
{% endblock %}
{% block js %}
{{ super() }}
<script src="{{url_for('admin.static',filename='ajax/libs/jasny/jasny-bootstrap.min.js')}}?v=3.1.3"></script>
<script src="{{url_for('admin.static',filename='ajax/libs/summernote/summernote.min.js')}}"></script>
<script src="{{url_for('admin.static',filename='ajax/libs/summernote/summernote-zh-CN.js')}}"></script>
<script type="text/javascript">

	$(function () {
		{% if d.col_type == 'richtext' %}
		$('.summernote').summernote({
			lang: 'zh-CN',
			callbacks: {
				onImageUpload: function (files) {
					//上传图片到服务器
					var formData = new FormData();
					formData.append('file', files[0]);
					$.modal.loading('图片上传中');
					$.ajax({
						url: "{{url_for('admin.upload')}}",//后台文件上传接口
						type: 'POST',
						data: formData,
						processData: false,
						contentType: false,
						success: function (resp) {
							$.modal.closeLoading();
							console.log(resp)
							$('.summernote').summernote('insertImage', resp.data, '');
						},
						complete: function (xhr, status) {
							$.modal.closeLoading();
						}
					});
				}
			},
		});
		{% endif %}

		$('#col_type').on('change', function () {
			if ($(this).val() == 'file') { //文件输入类型
				var html = ' \
					<div class="fileinput fileinput-new input-group" data-provides="fileinput"> \
                        <div class="form-control" data-trigger="fileinput"><i class="glyphicon glyphicon-file fileinput-exists"></i> <span class="fileinput-filename"></span></div> \
                        <span class="input-group-addon btn btn-white btn-file"><span class="fileinput-new">选择文件</span><span class="fileinput-exists">更改</span><input type="file" id="svalue" name="svalue"></span> \
                        <a href="#" class="input-group-addon btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a> \
                    </div> \
				';
				$('#input_type').html(html);
			} else if ($(this).val() == 'richtext') {
				var html = '<textarea class="form-control summernote" name="svalue" id="svalue" value="" required></textarea>';
				$('#input_type').html(html);
				$('.summernote').summernote({
					lang: 'zh-CN',
					callbacks: {
						onImageUpload: function (files) {
							//上传图片到服务器
							var formData = new FormData();
							formData.append('file', files[0]);
							$.modal.loading('图片上传中');
							$.ajax({
								url: "{{url_for('admin.upload')}}",//后台文件上传接口
								type: 'POST',
								data: formData,
								processData: false,
								contentType: false,
								success: function (resp) {
									$.modal.closeLoading();
									console.log(resp)
									$('.summernote').summernote('insertImage', resp.data, '');
								},
								complete: function (xhr, status) {
									$.modal.closeLoading();
								}
							});
						}
					},
				});
				$('#svalue').html($('#origin_svalue').val())
			} else {
				var html = '<textarea class="form-control" name="svalue" id="svalue" value="" required></textarea>';
				$('#input_type').html(html);
				$('#svalue').html($('#origin_svalue').val())
			}
		});
	});

	$("#form").validate({

	});

	function submitHandler() {
		if ($.validate.form()) {
			$.operate.save("{{url_for('admin.sys.setting.edit')}}", new FormData(document.getElementById('form')));
		}
	}

</script>
{% endblock %}